package com.chinaisafe.user.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.chinaisafe.base.common.annotation.OperationLog;
import com.chinaisafe.base.common.enums.BusinessTypeEnum;
import com.chinaisafe.base.common.validated.AddGroup;
import com.chinaisafe.base.common.validated.UpdateGroup;
import com.chinaisafe.base.common.vo.Answer;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.chinaisafe.user.vo.request.SysDeptDimensionReqVO;
import com.chinaisafe.user.vo.response.SysDeptDimensionRespVO;
import org.springframework.validation.annotation.Validated;
import com.chinaisafe.user.service.SysDeptDimensionService;
import org.springframework.web.bind.annotation.RestController;

/**
 * SysDeptDimensionController
 * Description：部门维度接口层
 *
 * @author tby
 * @date  2024-07-16 14:28:47
 */
@RestController
@RequestMapping("/sysDeptDimension")
@Tag(name = "部门维度接口层", description = "部门维度接口层")
public class SysDeptDimensionController {

    @Autowired
    private SysDeptDimensionService sysDeptDimensionService;

    @GetMapping("/pageList")
    @Operation(summary = "获取部门维度分页列表", description = "获取部门维度分页列表")
    public Answer<IPage<SysDeptDimensionRespVO>> pageList(SysDeptDimensionReqVO sysDeptDimensionReqVO) {
        IPage<SysDeptDimensionRespVO> pageList = sysDeptDimensionService.getPageList(sysDeptDimensionReqVO);
        return Answer.success("获取成功", pageList);
    }

    @PostMapping()
    @Operation(summary = "新增部门维度", description = "新增部门维度")
    @OperationLog(title = "部门维度-新增", businessType = BusinessTypeEnum.INSERT)
    public Answer<SysDeptDimensionRespVO> add(@RequestBody @Validated(AddGroup.class) SysDeptDimensionReqVO sysDeptDimensionReqVO) {
        SysDeptDimensionRespVO sysDeptDimensionRespVO = sysDeptDimensionService.add(sysDeptDimensionReqVO);
        return Answer.success("保存成功", sysDeptDimensionRespVO);
    }

    @PutMapping()
    @Operation(summary = "根据id编辑部门维度", description = "根据id编辑部门维度")
    @OperationLog(title = "部门维度-根据id编辑", businessType = BusinessTypeEnum.UPDATE)
    public Answer<SysDeptDimensionRespVO> update(@RequestBody @Validated(UpdateGroup.class) SysDeptDimensionReqVO sysDeptDimensionReqVO) {
        SysDeptDimensionRespVO sysDeptDimensionRespVO = sysDeptDimensionService.update(sysDeptDimensionReqVO);
        return Answer.success("修改成功", sysDeptDimensionRespVO);
    }

    @GetMapping("/{sysDeptDimensionId}")
    @Operation(summary = "根据id获取部门维度", description = "根据id获取部门维度")
    public Answer<SysDeptDimensionRespVO> getDetailById(@PathVariable Long sysDeptDimensionId) {
        SysDeptDimensionRespVO sysDeptDimensionRespVO = sysDeptDimensionService.getDetailById(sysDeptDimensionId);
        return Answer.success("获取成功", sysDeptDimensionRespVO);
    }

    @DeleteMapping()
    @Operation(summary = "根据id删除部门维度", description = "根据id删除部门维度")
    @OperationLog(title = "部门维度-根据id删除", businessType = BusinessTypeEnum.DELETE)
    public Answer<Void> deleteByIds(@RequestParam("ids") Long[] ids) {
        sysDeptDimensionService.deleteByIds(ids);
        return Answer.success("删除成功");
    }
}

